﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
namespace CoreSystem.Renderer
{
public class Renderer : ToolStripProfessionalRenderer
    {
        // Fields
        private static Color _arrowDark = Color.FromArgb(0x40, 70, 90);
        private static Color _arrowDisabled = _c1;
        private static Color _arrowLight = Color.FromArgb(0x6a, 0x7e, 0xc5);
        private static Color _c1 = Color.FromArgb(0xa7, 0xa7, 0xa7);
        private static Color _c2 = Color.FromArgb(0x15, 0x42, 0x8b);
        private static Color _c3 = Color.FromArgb(0x4c, 0x53, 0x5c);
        private static Color _c4 = Color.FromArgb(250, 250, 250);
        private static Color _c5 = Color.FromArgb(0xf8, 0xf8, 0xf8);
        private static Color _c6 = Color.FromArgb(0xf3, 0xf3, 0xf3);
        private static int _checkInset = 1;
        private static Color _contextCheckBorder = Color.FromArgb(0xf2, 0x95, 0x36);
        private static Color _contextCheckTick = Color.FromArgb(0x42, 0x4b, 0x8a);
        private static float _contextCheckTickThickness = 1.6f;
        private static Color _contextMenuBack = _c4;
        private static float _cutContextMenu = 0f;
        private static float _cutMenuItemBack = 1.2f;
        private static float _cutToolItemMenu = 1f;
        private static Color _gripDark = Color.FromArgb(0x72, 0x98, 0xcc);
        private static Color _gripLight = _c5;
        private static int _gripLines = 3;
        private static int _gripMove = 4;
        private static int _gripOffset = 1;
        private static int _gripSize = 3;
        private static int _gripSquare = 2;
        private static GradientItemColors _itemContextItemEnabledColors = new GradientItemColors(_r1, _r2, _r3, _r4, _r5, _r6, _r7, _r8, Color.FromArgb(0xd9, 0xcb, 150), Color.FromArgb(0xc0, 0xa7, 0x76));
        private static GradientItemColors _itemDisabledColors = new GradientItemColors(_c4, _c6, Color.FromArgb(0xec, 0xec, 0xec), Color.FromArgb(230, 230, 230), _c6, Color.FromArgb(0xe0, 0xe0, 0xe0), Color.FromArgb(200, 200, 200), Color.FromArgb(210, 210, 210), Color.FromArgb(0xd4, 0xd4, 0xd4), Color.FromArgb(0xc3, 0xc3, 0xc3));
        private static GradientItemColors _itemToolItemCheckedColors = new GradientItemColors(_rL, _rM, _rN, _rO, _rP, _rQ, _rR, _rS, _r9, _rA);
        private static GradientItemColors _itemToolItemCheckPressColors = new GradientItemColors(_rT, _rU, _rV, _rW, _rX, _rI, _rY, _rZ, _r9, _rA);
        private static GradientItemColors _itemToolItemPressedColors = new GradientItemColors(_rD, _rE, _rF, _rG, _rH, _rI, _rJ, _rK, _r9, _rA);
        private static GradientItemColors _itemToolItemSelectedColors = new GradientItemColors(_r1, _r2, _r3, _r4, _r5, _r6, _r7, _r8, _r9, _rA);
        private static int _marginInset = 2;
        private static Color _r1 = Color.FromArgb(0xff, 0xff, 0xfb);
        private static Color _r2 = Color.FromArgb(0xff, 0xf9, 0xe3);
        private static Color _r3 = Color.FromArgb(0xff, 0xf2, 0xc9);
        private static Color _r4 = Color.FromArgb(0xff, 0xf8, 0xb5);
        private static Color _r5 = Color.FromArgb(0xff, 0xfc, 0xe5);
        private static Color _r6 = Color.FromArgb(0xff, 0xeb, 0xa6);
        private static Color _r7 = Color.FromArgb(0xff, 0xd5, 0x67);
        private static Color _r8 = Color.FromArgb(0xff, 0xe4, 0x91);
        private static Color _r9 = Color.FromArgb(160, 0xbc, 0xe4);
        private static Color _rA = Color.FromArgb(0x79, 0x99, 0xc2);
        private static Color _rB = Color.FromArgb(0xb6, 190, 0xc0);
        private static Color _rC = Color.FromArgb(0x9b, 0xa3, 0xa7);
        private static Color _rD = Color.FromArgb(0xe9, 0xa8, 0x61);
        private static Color _rE = Color.FromArgb(0xf7, 0xa4, 0x27);
        private static Color _rF = Color.FromArgb(0xf6, 0x9c, 0x18);
        private static Color _rG = Color.FromArgb(0xfd, 0xad, 0x11);
        private static Color _rH = Color.FromArgb(0xfe, 0xb9, 0x6c);
        private static Color _rI = Color.FromArgb(0xfd, 0xa4, 0x61);
        private static Color _rJ = Color.FromArgb(0xfc, 0x8f, 0x3d);
        private static Color _rK = Color.FromArgb(0xff, 0xd0, 0x86);
        private static Color _rL = Color.FromArgb(0xf9, 0xc0, 0x67);
        private static Color _rM = Color.FromArgb(250, 0xc3, 0x5d);
        private static Color _rN = Color.FromArgb(0xf8, 190, 0x51);
        private static Color _rO = Color.FromArgb(0xff, 0xd0, 0x31);
        private static Color _rP = Color.FromArgb(0xfe, 0xd6, 0xa8);
        private static Color _rQ = Color.FromArgb(0xfc, 180, 100);
        private static Color _rR = Color.FromArgb(0xfc, 0xa1, 0x36);
        private static Color _rS = Color.FromArgb(0xfe, 0xee, 170);
        private static Color _rT = Color.FromArgb(0xf9, 0xca, 0x71);
        private static Color _rU = Color.FromArgb(250, 0xcd, 0x67);
        private static Color _rV = Color.FromArgb(0xf8, 200, 0x5b);
        private static Color _rW = Color.FromArgb(0xff, 0xda, 0x3b);
        private static Color _rX = Color.FromArgb(0xfe, 0xb9, 0x6c);
        private static Color _rY = Color.FromArgb(0xfc, 0xa1, 0x36);
        private static Color _rZ = Color.FromArgb(0xfe, 0xee, 170);
        private static int _separatorInset = 0x1f;
        private static Color _separatorMenuDark = Color.FromArgb(0xc5, 0xc5, 0xc5);
        private static Color _separatorMenuLight = Color.FromArgb(0xf5, 0xf5, 0xf5);
        private static Blend _statusStripBlend = new Blend();
        private static Color _statusStripBorderDark = Color.FromArgb(0x56, 0x7d, 0xb0);
        private static Color _statusStripBorderLight = Color.White;
        private static Color _textContextMenuItem = _c2;
        private static Color _textDisabled = _c1;
        private static Color _textMenuStripItem = _c2;
        private static Color _textStatusStripItem = _c2;

        // Methods
        static Renderer()
        {
            _statusStripBlend.Positions = new float[] { 0f, 0.25f, 0.25f, 0.57f, 0.86f, 1f };
            _statusStripBlend.Factors = new float[] { 0.1f, 0.6f, 1f, 0.4f, 0f, 0.95f };
        }

        public Renderer() : base(new ColorTable())
        {
        }

        private GraphicsPath CreateArrowPath(ToolStripItem item, Rectangle rect, ArrowDirection direction)
        {
            int num;
            int num2;
            if ((direction == ArrowDirection.Left) || (direction == ArrowDirection.Right))
            {
                num = rect.Right - ((rect.Width - 4) / 2);
                num2 = rect.Y + (rect.Height / 2);
            }
            else
            {
                num = rect.X + (rect.Width / 2);
                num2 = rect.Bottom - ((rect.Height - 3) / 2);
                if ((item is ToolStripDropDownButton) && (item.RightToLeft == RightToLeft.Yes))
                {
                    num++;
                }
            }
            GraphicsPath path = new GraphicsPath();
            switch (direction)
            {
                case ArrowDirection.Left:
                    path.AddLine(num - 4, num2, num, num2 - 4);
                    path.AddLine(num, num2 - 4, num, num2 + 4);
                    path.AddLine(num, num2 + 4, num - 4, num2);
                    return path;

                case ArrowDirection.Up:
                    path.AddLine(num + 3f, (float) num2, num - 3f, (float) num2);
                    path.AddLine(num - 3f, (float) num2, (float) num, num2 - 4f);
                    path.AddLine((float) num, num2 - 4f, num + 3f, (float) num2);
                    return path;

                case ArrowDirection.Right:
                    path.AddLine(num, num2, num - 4, num2 - 4);
                    path.AddLine((int) (num - 4), (int) (num2 - 4), (int) (num - 4), (int) (num2 + 4));
                    path.AddLine(num - 4, num2 + 4, num, num2);
                    return path;

                case ArrowDirection.Down:
                    path.AddLine((float) (num + 3f), (float) (num2 - 3f), (float) (num - 2f), (float) (num2 - 3f));
                    path.AddLine(num - 2f, num2 - 3f, (float) num, (float) num2);
                    path.AddLine((float) num, (float) num2, num + 3f, num2 - 3f);
                    return path;
            }
            return path;
        }

        private GraphicsPath CreateBorderPath(Rectangle rect, float cut)
        {
            rect.Width--;
            rect.Height--;
            GraphicsPath path = new GraphicsPath();
            path.AddLine(rect.Left + cut, (float) rect.Top, rect.Right - cut, (float) rect.Top);
            path.AddLine(rect.Right - cut, (float) rect.Top, (float) rect.Right, rect.Top + cut);
            path.AddLine((float) rect.Right, rect.Top + cut, (float) rect.Right, rect.Bottom - cut);
            path.AddLine((float) rect.Right, rect.Bottom - cut, rect.Right - cut, (float) rect.Bottom);
            path.AddLine(rect.Right - cut, (float) rect.Bottom, rect.Left + cut, (float) rect.Bottom);
            path.AddLine(rect.Left + cut, (float) rect.Bottom, (float) rect.Left, rect.Bottom - cut);
            path.AddLine((float) rect.Left, rect.Bottom - cut, (float) rect.Left, rect.Top + cut);
            path.AddLine((float) rect.Left, rect.Top + cut, rect.Left + cut, (float) rect.Top);
            return path;
        }

        private GraphicsPath CreateBorderPath(Rectangle rect, Rectangle exclude, float cut)
        {
            if (exclude.IsEmpty)
            {
                return this.CreateBorderPath(rect, cut);
            }
            rect.Width--;
            rect.Height--;
            List<PointF> list = new List<PointF>();
            float x = rect.X;
            float y = rect.Y;
            float right = rect.Right;
            float bottom = rect.Bottom;
            float num5 = rect.X + cut;
            float num6 = rect.Right - cut;
            float num7 = rect.Y + cut;
            float num8 = rect.Bottom - cut;
            float num9 = (cut == 0f) ? 1f : cut;
            if ((rect.Y >= exclude.Top) && (rect.Y <= exclude.Bottom))
            {
                float num10 = (exclude.X - 1) - cut;
                float num11 = exclude.Right + cut;
                if (num5 <= num10)
                {
                    list.Add(new PointF(num5, y));
                    list.Add(new PointF(num10, y));
                    list.Add(new PointF(num10 + cut, y - num9));
                }
                else
                {
                    num10 = exclude.X - 1;
                    list.Add(new PointF(num10, y));
                    list.Add(new PointF(num10, y - num9));
                }
                if (num6 > num11)
                {
                    list.Add(new PointF(num11 - cut, y - num9));
                    list.Add(new PointF(num11, y));
                    list.Add(new PointF(num6, y));
                }
                else
                {
                    num11 = exclude.Right;
                    list.Add(new PointF(num11, y - num9));
                    list.Add(new PointF(num11, y));
                }
            }
            else
            {
                list.Add(new PointF(num5, y));
                list.Add(new PointF(num6, y));
            }
            list.Add(new PointF(right, num7));
            list.Add(new PointF(right, num8));
            list.Add(new PointF(num6, bottom));
            list.Add(new PointF(num5, bottom));
            list.Add(new PointF(x, num8));
            list.Add(new PointF(x, num7));
            GraphicsPath path = new GraphicsPath();
            for (int i = 1; i < list.Count; i++)
            {
                path.AddLine(list[i - 1], list[i]);
            }
            path.AddLine(list[list.Count - 1], list[0]);
            return path;
        }

        private GraphicsPath CreateClipBorderPath(Rectangle rect, float cut)
        {
            rect.Width++;
            rect.Height++;
            return this.CreateBorderPath(rect, cut);
        }

        private GraphicsPath CreateClipBorderPath(Rectangle rect, Rectangle exclude, float cut)
        {
            rect.Width++;
            rect.Height++;
            return this.CreateBorderPath(rect, exclude, cut);
        }

        private GraphicsPath CreateIndeterminatePath(Rectangle rect)
        {
            int num = rect.X + (rect.Width / 2);
            int num2 = rect.Y + (rect.Height / 2);
            GraphicsPath path = new GraphicsPath();
            path.AddLine(num - 3, num2, num, num2 - 3);
            path.AddLine(num, num2 - 3, num + 3, num2);
            path.AddLine(num + 3, num2, num, num2 + 3);
            path.AddLine(num, num2 + 3, num - 3, num2);
            return path;
        }

        private GraphicsPath CreateInsideBorderPath(Rectangle rect, float cut)
        {
            rect.Inflate(-1, -1);
            return this.CreateBorderPath(rect, cut);
        }

        private GraphicsPath CreateInsideBorderPath(Rectangle rect, Rectangle exclude, float cut)
        {
            rect.Inflate(-1, -1);
            return this.CreateBorderPath(rect, exclude, cut);
        }

        private GraphicsPath CreateTickPath(Rectangle rect)
        {
            int num = rect.X + (rect.Width / 2);
            int num2 = rect.Y + (rect.Height / 2);
            GraphicsPath path = new GraphicsPath();
            path.AddLine(num - 4, num2, num - 2, num2 + 4);
            path.AddLine((int) (num - 2), (int) (num2 + 4), (int) (num + 3), (int) (num2 - 5));
            return path;
        }

        private void DrawContextMenuHeader(Graphics g, ToolStripItem item)
        {
            Rectangle rect = new Rectangle(Point.Empty, item.Bounds.Size);
            using (GraphicsPath path = this.CreateBorderPath(rect, _cutToolItemMenu))
            {
                using (this.CreateInsideBorderPath(rect, _cutToolItemMenu))
                {
                    using (GraphicsPath path3 = this.CreateClipBorderPath(rect, _cutToolItemMenu))
                    {
                        using (new UseClipping(g, path3))
                        {
                            using (SolidBrush brush = new SolidBrush(_separatorMenuLight))
                            {
                                g.FillPath(brush, path);
                            }
                            using (Pen pen = new Pen(base.ColorTable.MenuBorder))
                            {
                                g.DrawPath(pen, path);
                            }
                        }
                    }
                }
            }
        }

        private void DrawGradientBack(Graphics g, Rectangle backRect, GradientItemColors colors)
        {
            backRect.Inflate(-1, -1);
            int height = backRect.Height / 2;
            Rectangle rect = new Rectangle(backRect.X, backRect.Y, backRect.Width, height);
            Rectangle rectangle2 = new Rectangle(backRect.X, backRect.Y + height, backRect.Width, backRect.Height - height);
            Rectangle rectangle3 = rect;
            Rectangle rectangle4 = rectangle2;
            rectangle3.Inflate(1, 1);
            rectangle4.Inflate(1, 1);
            using (LinearGradientBrush brush = new LinearGradientBrush(rectangle3, colors.InsideTop1, colors.InsideTop2, 90f))
            {
                using (LinearGradientBrush brush2 = new LinearGradientBrush(rectangle4, colors.InsideBottom1, colors.InsideBottom2, 90f))
                {
                    g.FillRectangle(brush, rect);
                    g.FillRectangle(brush2, rectangle2);
                }
            }
            height = backRect.Height / 2;
            rect = new Rectangle(backRect.X, backRect.Y, backRect.Width, height);
            rectangle2 = new Rectangle(backRect.X, backRect.Y + height, backRect.Width, backRect.Height - height);
            rectangle3 = rect;
            rectangle4 = rectangle2;
            rectangle3.Inflate(1, 1);
            rectangle4.Inflate(1, 1);
            using (LinearGradientBrush brush3 = new LinearGradientBrush(rectangle3, colors.FillTop1, colors.FillTop2, 90f))
            {
                using (LinearGradientBrush brush4 = new LinearGradientBrush(rectangle4, colors.FillBottom1, colors.FillBottom2, 90f))
                {
                    backRect.Inflate(-1, -1);
                    height = backRect.Height / 2;
                    rect = new Rectangle(backRect.X, backRect.Y, backRect.Width, height);
                    rectangle2 = new Rectangle(backRect.X, backRect.Y + height, backRect.Width, backRect.Height - height);
                    g.FillRectangle(brush3, rect);
                    g.FillRectangle(brush4, rectangle2);
                }
            }
        }

        private void DrawGradientBorder(Graphics g, Rectangle backRect, GradientItemColors colors)
        {
            using (new UseAntiAlias(g))
            {
                Rectangle rect = backRect;
                rect.Inflate(1, 1);
                using (LinearGradientBrush brush = new LinearGradientBrush(rect, colors.Border1, colors.Border2, 90f))
                {
                    brush.SetSigmaBellShape(0.5f);
                    using (Pen pen = new Pen(brush))
                    {
                        using (GraphicsPath path = this.CreateBorderPath(backRect, _cutMenuItemBack))
                        {
                            g.DrawPath(pen, path);
                        }
                    }
                }
            }
        }

        private void DrawGradientContextMenuItem(Graphics g, ToolStripItem item, GradientItemColors colors)
        {
            Rectangle backRect = new Rectangle(2, 0, item.Bounds.Width - 3, item.Bounds.Height);
            this.DrawGradientItem(g, backRect, colors);
        }

        private void DrawGradientItem(Graphics g, Rectangle backRect, GradientItemColors colors)
        {
            if ((backRect.Width > 0) && (backRect.Height > 0))
            {
                this.DrawGradientBack(g, backRect, colors);
                this.DrawGradientBorder(g, backRect, colors);
            }
        }

        private void DrawGradientToolItem(Graphics g, ToolStripItem item, GradientItemColors colors)
        {
            this.DrawGradientItem(g, new Rectangle(Point.Empty, item.Bounds.Size), colors);
        }

        private void DrawGradientToolSplitItem(Graphics g, ToolStripSplitButton splitButton, GradientItemColors colorsButton, GradientItemColors colorsDrop, GradientItemColors colorsSplit)
        {
            Rectangle rect = new Rectangle(Point.Empty, splitButton.Bounds.Size);
            Rectangle dropDownButtonBounds = splitButton.DropDownButtonBounds;
            if ((((rect.Width > 0) && (dropDownButtonBounds.Width > 0)) && (rect.Height > 0)) && (dropDownButtonBounds.Height > 0))
            {
                int x;
                Rectangle backRect = rect;
                if (dropDownButtonBounds.X > 0)
                {
                    backRect.Width = dropDownButtonBounds.Left;
                    dropDownButtonBounds.X--;
                    dropDownButtonBounds.Width++;
                    x = dropDownButtonBounds.X;
                }
                else
                {
                    backRect.Width -= dropDownButtonBounds.Width - 2;
                    backRect.X = dropDownButtonBounds.Right - 1;
                    dropDownButtonBounds.Width++;
                    x = dropDownButtonBounds.Right - 1;
                }
                using (this.CreateBorderPath(rect, _cutMenuItemBack))
                {
                    this.DrawGradientBack(g, backRect, colorsButton);
                    this.DrawGradientBack(g, dropDownButtonBounds, colorsDrop);
                    using (LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(rect.X + x, rect.Top, 1, rect.Height + 1), colorsSplit.Border1, colorsSplit.Border2, 90f))
                    {
                        brush.SetSigmaBellShape(0.5f);
                        using (Pen pen = new Pen(brush))
                        {
                            g.DrawLine(pen, (int) (rect.X + x), (int) (rect.Top + 1), (int) (rect.X + x), (int) (rect.Bottom - 1));
                        }
                    }
                    this.DrawGradientBorder(g, rect, colorsButton);
                }
            }
        }

        private void DrawGripGlyph(Graphics g, int x, int y, Brush darkBrush, Brush lightBrush)
        {
            g.FillRectangle(lightBrush, x + _gripOffset, y + _gripOffset, _gripSquare, _gripSquare);
            g.FillRectangle(darkBrush, x, y, _gripSquare, _gripSquare);
        }

        private void DrawSeparator(Graphics g, bool vertical, Rectangle rect, Pen lightPen, Pen darkPen, int horizontalInset, bool rtl)
        {
            int num;
            if (vertical)
            {
                num = rect.Width / 2;
                int y = rect.Y;
                int bottom = rect.Bottom;
                g.DrawLine(darkPen, num, y, num, bottom);
                g.DrawLine(lightPen, num + 1, y, num + 1, bottom);
            }
            else
            {
                int num4 = rect.Height / 2;
                num = rect.X + (rtl ? 0 : horizontalInset);
                int num5 = rect.Right - (rtl ? horizontalInset : 0);
                g.DrawLine(darkPen, num, num4, num5, num4);
                g.DrawLine(lightPen, num, num4 + 1, num5, num4 + 1);
            }
        }

        protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e)
        {
            if ((e.ArrowRectangle.Width > 0) && (e.ArrowRectangle.Height > 0))
            {
                using (GraphicsPath path = this.CreateArrowPath(e.Item, e.ArrowRectangle, e.Direction))
                {
                    RectangleF bounds = path.GetBounds();
                    bounds.Inflate(1f, 1f);
                    Color color = e.Item.Enabled ? _arrowLight : _arrowDisabled;
                    Color color2 = e.Item.Enabled ? _arrowDark : _arrowDisabled;
                    float angle = 0f;
                    switch (e.Direction)
                    {
                        case ArrowDirection.Left:
                            angle = 180f;
                            break;

                        case ArrowDirection.Up:
                            angle = 270f;
                            break;

                        case ArrowDirection.Right:
                            angle = 0f;
                            break;

                        case ArrowDirection.Down:
                            angle = 90f;
                            break;
                    }
                    using (LinearGradientBrush brush = new LinearGradientBrush(bounds, color, color2, angle))
                    {
                        e.Graphics.FillPath(brush, path);
                    }
                }
            }
        }

        protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
        {
            ToolStripButton item = (ToolStripButton) e.Item;
            if ((item.Selected || item.Pressed) || item.Checked)
            {
                this.RenderToolButtonBackground(e.Graphics, item, e.ToolStrip);
            }
        }

        protected override void OnRenderDropDownButtonBackground(ToolStripItemRenderEventArgs e)
        {
            if (e.Item.Selected || e.Item.Pressed)
            {
                this.RenderToolDropButtonBackground(e.Graphics, e.Item, e.ToolStrip);
            }
        }

        protected override void OnRenderImageMargin(ToolStripRenderEventArgs e)
        {
            if ((e.ToolStrip is ContextMenuStrip) || (e.ToolStrip is ToolStripDropDownMenu))
            {
                Rectangle affectedBounds = e.AffectedBounds;
                bool flag = e.ToolStrip.RightToLeft == RightToLeft.Yes;
                affectedBounds.Y += _marginInset;
                affectedBounds.Height -= _marginInset * 2;
                if (!flag)
                {
                    affectedBounds.X += _marginInset;
                }
                else
                {
                    affectedBounds.X += _marginInset / 2;
                }
                using (SolidBrush brush = new SolidBrush(base.ColorTable.ImageMarginGradientBegin))
                {
                    e.Graphics.FillRectangle(brush, affectedBounds);
                }
                using (Pen pen = new Pen(_separatorMenuLight))
                {
                    using (Pen pen2 = new Pen(_separatorMenuDark))
                    {
                        if (!flag)
                        {
                            e.Graphics.DrawLine(pen, affectedBounds.Right, affectedBounds.Top, affectedBounds.Right, affectedBounds.Bottom);
                            e.Graphics.DrawLine(pen2, affectedBounds.Right - 1, affectedBounds.Top, affectedBounds.Right - 1, affectedBounds.Bottom);
                        }
                        else
                        {
                            e.Graphics.DrawLine(pen, affectedBounds.Left - 1, affectedBounds.Top, affectedBounds.Left - 1, affectedBounds.Bottom);
                            e.Graphics.DrawLine(pen2, affectedBounds.Left, affectedBounds.Top, affectedBounds.Left, affectedBounds.Bottom);
                        }
                    }
                }
            }
            else
            {
                base.OnRenderImageMargin(e);
            }
        }

        protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e)
        {
            int num;
            Rectangle imageRectangle = e.ImageRectangle;
            imageRectangle.Inflate(1, 1);
            if (imageRectangle.Top > _checkInset)
            {
                num = imageRectangle.Top - _checkInset;
                imageRectangle.Y -= num;
                imageRectangle.Height += num;
            }
            if (imageRectangle.Height <= (e.Item.Bounds.Height - (_checkInset * 2)))
            {
                num = (e.Item.Bounds.Height - (_checkInset * 2)) - imageRectangle.Height;
                imageRectangle.Height += num;
            }
            using (new UseAntiAlias(e.Graphics))
            {
                using (GraphicsPath path = this.CreateBorderPath(imageRectangle, _cutMenuItemBack))
                {
                    using (SolidBrush brush = new SolidBrush(base.ColorTable.CheckBackground))
                    {
                        e.Graphics.FillPath(brush, path);
                    }
                    using (Pen pen = new Pen(_contextCheckBorder))
                    {
                        e.Graphics.DrawPath(pen, path);
                    }
                    if (e.Image != null)
                    {
                        GraphicsPath path2;
                        CheckState @unchecked = CheckState.Unchecked;
                        if (e.Item is ToolStripMenuItem)
                        {
                            ToolStripMenuItem item = (ToolStripMenuItem) e.Item;
                            @unchecked = item.CheckState;
                        }
                        switch (@unchecked)
                        {
                            case CheckState.Checked:
                                using (path2 = this.CreateTickPath(imageRectangle))
                                {
                                    using (Pen pen2 = new Pen(_contextCheckTick, _contextCheckTickThickness))
                                    {
                                        e.Graphics.DrawPath(pen2, path2);
                                    }
                                }
                                return;

                            case CheckState.Indeterminate:
                                using (path2 = this.CreateIndeterminatePath(imageRectangle))
                                {
                                    using (SolidBrush brush2 = new SolidBrush(_contextCheckTick))
                                    {
                                        e.Graphics.FillPath(brush2, path2);
                                    }
                                }
                                return;
                        }
                    }
                }
            }
        }

        protected override void OnRenderItemImage(ToolStripItemImageRenderEventArgs e)
        {
            if ((e.ToolStrip is ContextMenuStrip) || (e.ToolStrip is ToolStripDropDownMenu))
            {
                if (e.Image != null)
                {
                    if (e.Item.Enabled)
                    {
                        e.Graphics.DrawImage(e.Image, e.ImageRectangle);
                    }
                    else
                    {
                        ControlPaint.DrawImageDisabled(e.Graphics, e.Image, e.ImageRectangle.X, e.ImageRectangle.Y, Color.Transparent);
                    }
                }
            }
            else
            {
                base.OnRenderItemImage(e);
            }
        }

        protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
        {
            if ((((e.ToolStrip is MenuStrip) || (e.ToolStrip != null)) || (e.ToolStrip is ContextMenuStrip)) || (e.ToolStrip is ToolStripDropDownMenu))
            {
                if (!e.Item.Enabled)
                {
                    e.TextColor = _textDisabled;
                }
                else if (!((!(e.ToolStrip is MenuStrip) || e.Item.Pressed) || e.Item.Selected))
                {
                    e.TextColor = _textMenuStripItem;
                }
                else if (!((!(e.ToolStrip is StatusStrip) || e.Item.Pressed) || e.Item.Selected))
                {
                    e.TextColor = _textStatusStripItem;
                }
                else
                {
                    e.TextColor = _textContextMenuItem;
                }
                using (new UseClearTypeGridFit(e.Graphics))
                {
                    base.OnRenderItemText(e);
                }
            }
            else
            {
                base.OnRenderItemText(e);
            }
        }

        protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
        {
            if (((e.ToolStrip is MenuStrip) || (e.ToolStrip is ContextMenuStrip)) || (e.ToolStrip is ToolStripDropDownMenu))
            {
                if (e.Item.Pressed && (e.ToolStrip is MenuStrip))
                {
                    this.DrawContextMenuHeader(e.Graphics, e.Item);
                }
                else if (e.Item.Selected)
                {
                    if (e.Item.Enabled)
                    {
                        if (e.ToolStrip is MenuStrip)
                        {
                            this.DrawGradientToolItem(e.Graphics, e.Item, _itemToolItemSelectedColors);
                        }
                        else
                        {
                            this.DrawGradientContextMenuItem(e.Graphics, e.Item, _itemContextItemEnabledColors);
                        }
                    }
                    else
                    {
                        Point pt = e.ToolStrip.PointToClient(Control.MousePosition);
                        if (!e.Item.Bounds.Contains(pt))
                        {
                            if (e.ToolStrip is MenuStrip)
                            {
                                this.DrawGradientToolItem(e.Graphics, e.Item, _itemDisabledColors);
                            }
                            else
                            {
                                this.DrawGradientContextMenuItem(e.Graphics, e.Item, _itemDisabledColors);
                            }
                        }
                    }
                }
            }
            else
            {
                base.OnRenderMenuItemBackground(e);
            }
        }

        protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e)
        {
            Pen pen;
            Pen pen2;
            if ((e.ToolStrip is ContextMenuStrip) || (e.ToolStrip is ToolStripDropDownMenu))
            {
                using (pen = new Pen(_separatorMenuLight))
                {
                    using (pen2 = new Pen(_separatorMenuDark))
                    {
                        this.DrawSeparator(e.Graphics, e.Vertical, e.Item.Bounds, pen, pen2, _separatorInset, e.ToolStrip.RightToLeft == RightToLeft.Yes);
                    }
                }
            }
            else if (e.ToolStrip is StatusStrip)
            {
                using (pen = new Pen(base.ColorTable.SeparatorLight))
                {
                    using (pen2 = new Pen(base.ColorTable.SeparatorDark))
                    {
                        this.DrawSeparator(e.Graphics, e.Vertical, e.Item.Bounds, pen, pen2, 0, false);
                    }
                }
            }
            else
            {
                base.OnRenderSeparator(e);
            }
        }

        protected override void OnRenderSplitButtonBackground(ToolStripItemRenderEventArgs e)
        {
            if (e.Item.Selected || e.Item.Pressed)
            {
                ToolStripSplitButton item = (ToolStripSplitButton) e.Item;
                this.RenderToolSplitButtonBackground(e.Graphics, item, e.ToolStrip);
                Rectangle dropDownButtonBounds = item.DropDownButtonBounds;
                this.OnRenderArrow(new ToolStripArrowRenderEventArgs(e.Graphics, item, dropDownButtonBounds, SystemColors.ControlText, ArrowDirection.Down));
            }
            else
            {
                base.OnRenderSplitButtonBackground(e);
            }
        }

        protected override void OnRenderStatusStripSizingGrip(ToolStripRenderEventArgs e)
        {
            using (SolidBrush brush = new SolidBrush(_gripDark))
            {
                using (SolidBrush brush2 = new SolidBrush(_gripLight))
                {
                    bool flag = e.ToolStrip.RightToLeft == RightToLeft.Yes;
                    int y = (e.AffectedBounds.Bottom - (_gripSize * 2)) + 1;
                    for (int i = _gripLines; i >= 1; i--)
                    {
                        int x = flag ? (e.AffectedBounds.Left + 1) : ((e.AffectedBounds.Right - (_gripSize * 2)) + 1);
                        for (int j = 0; j < i; j++)
                        {
                            this.DrawGripGlyph(e.Graphics, x, y, brush, brush2);
                            x -= flag ? -_gripMove : _gripMove;
                        }
                        y -= _gripMove;
                    }
                }
            }
        }

        protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
        {
            if ((e.ToolStrip is ContextMenuStrip) || (e.ToolStrip is ToolStripDropDownMenu))
            {
                using (GraphicsPath path = this.CreateBorderPath(e.AffectedBounds, _cutContextMenu))
                {
                    using (GraphicsPath path2 = this.CreateClipBorderPath(e.AffectedBounds, _cutContextMenu))
                    {
                        using (new UseClipping(e.Graphics, path2))
                        {
                            using (SolidBrush brush = new SolidBrush(_contextMenuBack))
                            {
                                e.Graphics.FillPath(brush, path);
                            }
                        }
                        return;
                    }
                }
            }
            if (e.ToolStrip is StatusStrip)
            {
                RectangleF rect = new RectangleF(0f, 1.5f, (float) e.ToolStrip.Width, (float) (e.ToolStrip.Height - 2));
                if ((rect.Width > 0f) && (rect.Height > 0f))
                {
                    using (LinearGradientBrush brush2 = new LinearGradientBrush(rect, base.ColorTable.StatusStripGradientBegin, base.ColorTable.StatusStripGradientEnd, 90f))
                    {
                        brush2.Blend = _statusStripBlend;
                        e.Graphics.FillRectangle(brush2, rect);
                    }
                }
            }
            else
            {
                base.OnRenderToolStripBackground(e);
            }
        }

        protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
        {
            if ((e.ToolStrip is ContextMenuStrip) || (e.ToolStrip is ToolStripDropDownMenu))
            {
                if (!e.ConnectedArea.IsEmpty)
                {
                    using (SolidBrush brush = new SolidBrush(_contextMenuBack))
                    {
                        e.Graphics.FillRectangle(brush, e.ConnectedArea);
                    }
                }
                using (GraphicsPath path = this.CreateBorderPath(e.AffectedBounds, e.ConnectedArea, _cutContextMenu))
                {
                    using (GraphicsPath path2 = this.CreateInsideBorderPath(e.AffectedBounds, e.ConnectedArea, _cutContextMenu))
                    {
                        using (GraphicsPath path3 = this.CreateClipBorderPath(e.AffectedBounds, e.ConnectedArea, _cutContextMenu))
                        {
                            using (Pen pen = new Pen(base.ColorTable.MenuBorder))
                            {
                                using (Pen pen2 = new Pen(_separatorMenuLight))
                                {
                                    using (new UseClipping(e.Graphics, path3))
                                    {
                                        using (new UseAntiAlias(e.Graphics))
                                        {
                                            e.Graphics.DrawPath(pen2, path2);
                                            e.Graphics.DrawPath(pen, path);
                                        }
                                        e.Graphics.DrawLine(pen, e.AffectedBounds.Right, e.AffectedBounds.Bottom, e.AffectedBounds.Right - 1, e.AffectedBounds.Bottom - 1);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (e.ToolStrip is StatusStrip)
            {
                using (Pen pen3 = new Pen(_statusStripBorderDark))
                {
                    using (Pen pen4 = new Pen(_statusStripBorderLight))
                    {
                        e.Graphics.DrawLine(pen3, 0, 0, e.ToolStrip.Width, 0);
                        e.Graphics.DrawLine(pen4, 0, 1, e.ToolStrip.Width, 1);
                    }
                }
            }
            else
            {
                base.OnRenderToolStripBorder(e);
            }
        }

        protected override void OnRenderToolStripContentPanelBackground(ToolStripContentPanelRenderEventArgs e)
        {
            base.OnRenderToolStripContentPanelBackground(e);
            if ((e.ToolStripContentPanel.Width > 0) && (e.ToolStripContentPanel.Height > 0))
            {
                using (LinearGradientBrush brush = new LinearGradientBrush(e.ToolStripContentPanel.ClientRectangle, base.ColorTable.ToolStripContentPanelGradientEnd, base.ColorTable.ToolStripContentPanelGradientBegin, 90f))
                {
                    e.Graphics.FillRectangle(brush, e.ToolStripContentPanel.ClientRectangle);
                }
            }
        }

        private void RenderToolButtonBackground(Graphics g, ToolStripButton button, ToolStrip toolstrip)
        {
            if (button.Enabled)
            {
                if (button.Checked)
                {
                    if (button.Pressed)
                    {
                        this.DrawGradientToolItem(g, button, _itemToolItemPressedColors);
                    }
                    else if (button.Selected)
                    {
                        this.DrawGradientToolItem(g, button, _itemToolItemCheckPressColors);
                    }
                    else
                    {
                        this.DrawGradientToolItem(g, button, _itemToolItemCheckedColors);
                    }
                }
                else if (button.Pressed)
                {
                    this.DrawGradientToolItem(g, button, _itemToolItemPressedColors);
                }
                else if (button.Selected)
                {
                    this.DrawGradientToolItem(g, button, _itemToolItemSelectedColors);
                }
            }
            else if (button.Selected)
            {
                Point pt = toolstrip.PointToClient(Control.MousePosition);
                if (!button.Bounds.Contains(pt))
                {
                    this.DrawGradientToolItem(g, button, _itemDisabledColors);
                }
            }
        }

        private void RenderToolDropButtonBackground(Graphics g, ToolStripItem item, ToolStrip toolstrip)
        {
            if (item.Selected || item.Pressed)
            {
                if (item.Enabled)
                {
                    if (item.Pressed)
                    {
                        this.DrawContextMenuHeader(g, item);
                    }
                    else
                    {
                        this.DrawGradientToolItem(g, item, _itemToolItemSelectedColors);
                    }
                }
                else
                {
                    Point pt = toolstrip.PointToClient(Control.MousePosition);
                    if (!item.Bounds.Contains(pt))
                    {
                        this.DrawGradientToolItem(g, item, _itemDisabledColors);
                    }
                }
            }
        }

        private void RenderToolSplitButtonBackground(Graphics g, ToolStripSplitButton splitButton, ToolStrip toolstrip)
        {
            if (splitButton.Selected || splitButton.Pressed)
            {
                if (splitButton.Enabled)
                {
                    if (!(splitButton.Pressed || !splitButton.ButtonPressed))
                    {
                        this.DrawGradientToolSplitItem(g, splitButton, _itemToolItemPressedColors, _itemToolItemSelectedColors, _itemContextItemEnabledColors);
                    }
                    else if (!(!splitButton.Pressed || splitButton.ButtonPressed))
                    {
                        this.DrawContextMenuHeader(g, splitButton);
                    }
                    else
                    {
                        this.DrawGradientToolSplitItem(g, splitButton, _itemToolItemSelectedColors, _itemToolItemSelectedColors, _itemContextItemEnabledColors);
                    }
                }
                else
                {
                    Point pt = toolstrip.PointToClient(Control.MousePosition);
                    if (!splitButton.Bounds.Contains(pt))
                    {
                        this.DrawGradientToolItem(g, splitButton, _itemDisabledColors);
                    }
                }
            }
        }

        // Nested Types
        private class GradientItemColors
        {
            // Fields
            public Color Border1;
            public Color Border2;
            public Color FillBottom1;
            public Color FillBottom2;
            public Color FillTop1;
            public Color FillTop2;
            public Color InsideBottom1;
            public Color InsideBottom2;
            public Color InsideTop1;
            public Color InsideTop2;

            // Methods
            public GradientItemColors(Color insideTop1, Color insideTop2, Color insideBottom1, Color insideBottom2, Color fillTop1, Color fillTop2, Color fillBottom1, Color fillBottom2, Color border1, Color border2)
            {
                this.InsideTop1 = insideTop1;
                this.InsideTop2 = insideTop2;
                this.InsideBottom1 = insideBottom1;
                this.InsideBottom2 = insideBottom2;
                this.FillTop1 = fillTop1;
                this.FillTop2 = fillTop2;
                this.FillBottom1 = fillBottom1;
                this.FillBottom2 = fillBottom2;
                this.Border1 = border1;
                this.Border2 = border2;
            }
        }
    }

}
